<?php
/*
# ------------------------------------------------------------------------
# JA Mesolite for Joomla 1.5 - Version 1.2 - Licence Owner JA158198
# ------------------------------------------------------------------------
# Copyright (C) 2004-2009 J.O.O.M Solutions Co., Ltd. All Rights Reserved.
# @license - Copyrighted Commercial Software
# Author: J.O.O.M Solutions Co., Ltd
# Websites:  http://www.joomlart.com -  http://www.joomlancers.com
# This file may not be redistributed in whole or significant part.
# ------------------------------------------------------------------------
*/

defined( '_JEXEC' ) or die( 'Restricted access' );
require_once(JPATH_BASE.'/modules/mod_ja_vmproductslide/ja_vmproductslide/application.php');

$xheight = $params->get('xheight',400);
$xwidth = $params->get('xwidth',400);
$typeproduct = $params->get('typeproduct',0);
$numElem = $params->get('numElem',4);
$mode = $params->get('mode',1);
$catid = $params->get('catid','');
$show_price = $params->get('show_price',1);
$show_addtocart = $params->get('show_addtocart',1);
$auto = $params->get('auto',1);
$direction = $params->get('direction','left');
$delaytime = $params->get('delaytime',5000);
$animationtime = $params->get('animationtime',1000);
if($catid){
	$catid = explode(',',$catid);
	$catid = "'".implode("','",$catid)."'";
}
$database		=& JFactory::getDBO();
$javmslide = new JA_VMSlider($params, $database, $typeproduct,$show_addtocart,$show_price,$numElem);
$total = $javmslide->getTotal($catid);
if($total){
	if($total < $numElem) $numElem = $total;
	
	$filename = JPATH_SITE.DS.'templates/'.$mainframe->getTemplate().'/css/ja.vm.css';
	$css_path = JURI::base().'templates/'.$mainframe->getTemplate().'/css/';
	if(!file_exists($filename)){
		$css_path = JURI::base().'modules/mod_ja_vmproductslide/ja_vmproductslide/';
	}
		
	JHTML::stylesheet('ja.vm.css', $css_path);
	?>

	<script type="text/javascript" src="<?php echo JURI::base(); ?>modules/mod_ja_vmproductslide/ja_vmproductslide/ja.vmproductslide.js"></script>
	<script type="text/javascript">
		
		
		var jsslider<?php echo $module->id;  ?> = null;
	</script>
	
	<script type="text/javascript">
	//<!--[CDATA[
	function sliderInit<?php echo $module->id; ?> (){
		var ja_options={
		    w: <?php echo $xwidth; ?>,
		    h: <?php echo $xheight; ?>,
		    num_elem: <?php echo $numElem; ?>,
		    mode: '<?php echo $mode; ?>', //horizontal or virtical
		    direction: '<?php echo $direction; ?>', //horizontal: left or right; virtical: up or down
			total: <?php echo $total; ?>,
			url: '',
		    wrapper: 'ja-slider-center'+<?php echo $module->id; ?>,
		    duration: <?php echo $animationtime; ?>,
		    interval: <?php echo $delaytime; ?>,
			running: false,
		    auto: <?php echo $auto; ?>
		};

		jsslider<?php echo $module->id; ?> = new JS_Slider(ja_options);

		elems = $('ja-slider-center'+<?php echo $module->id; ?>).getElementsByClassName ('vm_element');
		for(i=0;i<elems.length;i++){
			jsslider<?php echo $module->id; ?>.update (elems[i].innerHTML, i);
		}
		jsslider<?php echo $module->id;  ?>.setPos(null);
		if(jsslider<?php echo $module->id; ?>.options.auto){
			jsslider<?php echo $module->id; ?>.nextRun();
		}
	}
	
	jaAddEvent(window, 'load', sliderInit<?php echo $module->id; ?>);
	
	function setDirection<?php echo $module->id; ?>(direction,ret){
		jsslider<?php echo $module->id; ?>.options.direction = direction;
		if(jsslider<?php echo $module->id; ?>.options.auto){
			if(ret){
				if(direction == 'right'){
					$('ja-slide-left-img'+<?php echo $module->id; ?>).src = '<?php echo JURI::base(); ?>modules/mod_ja_vmproductslide/ja_vmproductslide/img/re-left.gif';
				}else  {
					$('ja-slide-right-img'+<?php echo $module->id; ?>).src = '<?php echo JURI::base(); ?>modules/mod_ja_vmproductslide/ja_vmproductslide/img/re-right.gif';
				}
				jsslider<?php echo $module->id;  ?>.options.interval = <?php echo $delaytime; ?>;
				jsslider<?php echo $module->id;  ?>.options.duration = <?php echo $animationtime; ?>;
			}
			else{
				if(direction == 'right'){
					$('ja-slide-left-img'+<?php echo $module->id; ?>).src = '<?php echo JURI::base(); ?>modules/mod_ja_vmproductslide/ja_vmproductslide/img/re-left-hover.gif';
				}else  {
					$('ja-slide-right-img'+<?php echo $module->id; ?>).src = '<?php echo JURI::base(); ?>modules/mod_ja_vmproductslide/ja_vmproductslide/img/re-right-hover.gif';
				}
				jsslider<?php echo $module->id;  ?>.options.interval = 800;
				jsslider<?php echo $module->id;  ?>.options.duration = 500;
				jsslider<?php echo $module->id;  ?>.nextRun();
			}
		}
		else{
			if(ret){
				if(direction == 'right'){
					$('ja-slide-left-img'+<?php echo $module->id; ?>).src = '<?php echo JURI::base(); ?>modules/mod_ja_vmproductslide/ja_vmproductslide/img/re-left.gif';
				}else  {
					$('ja-slide-right-img'+<?php echo $module->id; ?>).src = '<?php echo JURI::base(); ?>modules/mod_ja_vmproductslide/ja_vmproductslide/img/re-right.gif';
				}
				jsslider<?php echo $module->id;  ?>.options.auto = 1;
			}
			else{
				if(direction == 'right'){
					$('ja-slide-left-img'+<?php echo $module->id; ?>).src = '<?php echo JURI::base(); ?>modules/mod_ja_vmproductslide/ja_vmproductslide/img/re-left-hover.gif';
				}else  {
					$('ja-slide-right-img'+<?php echo $module->id; ?>).src = '<?php echo JURI::base(); ?>modules/mod_ja_vmproductslide/ja_vmproductslide/img/re-right-hover.gif';
				}
				jsslider<?php echo $module->id;  ?>.options.interval = 500;
				jsslider<?php echo $module->id;  ?>.options.duration = 500;
				jsslider<?php echo $module->id;  ?>.options.auto = 1;
				jsslider<?php echo $module->id;  ?>.nextRun();
			}		
		}
	}
	//]]-->
	</script>

	<div id="ja-slider">
		
		<div class="ja-slider-center" id="ja-slider-center<?php echo $module->id; ?>">
		<?php $javmslide->genHTML($catid);?>
		</div>
		
	</div>
	<?php
}
else{
	echo '<div id="ja-slide-error">'.JText::_('JA VIRTURE MART ERROR: THERE IS NOT ANY PRODUCT IN THIS CATEGORY').' </div>';
}
?>

